import Vue from 'vue';
const that = Vue.prototype

let getBtnsId = (type) => {
  let authorityBtnsList = JSON.parse(sessionStorage.getItem('authorityBtnsList'))
  let btnParamId = ''
  let btnsTarget = _.find(authorityBtnsList, value => {
    return value.btnName == type
  })
  if (btnsTarget) btnParamId = btnsTarget.btnParamId
  return btnParamId
}

/* 校验当前按钮是否有权限 */
let handleGetPermission = (label, curMenuBtns, systematicBtns) => {
  if (!curMenuBtns) { return false }
  if (label == '导出分类') label = '导出';
  if (label == '重新编辑') label = '重新提交'; // 暂时方案，后续再处理
  let flag = true;
  const systemBtnList = JSON.parse(sessionStorage.getItem('systemBtnsList'));
  const systemBtnLabelList = systemBtnList.map(item => item.name);
  if (systemBtnLabelList.includes(label)) {
    flag = curMenuBtns.indexOf(systematicBtns[that.$md5(label)]) > -1;
  }
  return flag;
}

export {
  getBtnsId,
  handleGetPermission
}
